Now that we've learned about NumPy let's test your knowledge. We'll start off with a few simple tasks and then you'll be asked some more complicated questions.
IMPORTANT NOTE! Make sure you don't run the cells directly above the example output shown, otherwise you will end up writing over the example output!
In [1]:
import numpy as np
In [2]:
np.zeros(10)# CODE HERE
Out[2]:
In [3]:
np.zeros(10)
Out[3]:
In [4]:
np.ones(10)
Out[4]:
In [5]:
np.ones(10)
Out[5]:
In [12]:
np.full(10, 5)
Out[12]:
In [13]:
np.full(10, 5.0)
Out[13]:
In [15]:
np.arange(10, 51, 1)
Out[15]:
In [5]:
Out[5]:
In [ ]:
# CODE HERE
In [16]:
np.arange(10, 51, 2)
Out[16]:
In [18]:
np.arange(0, 9, 1).reshape(3, 3)
Out[18]:
In [7]:
Out[7]:
In [19]:
np.eye(3)
Out[19]:
In [8]:
Out[8]:
In [ ]:
# CODE HERE
In [20]:
np.random.random(1)
Out[20]:
In [24]:
np.random.randn(25)
Out[24]:
In [33]:
Out[33]:
In [35]:
np.arange(0.01, 1.01, 0.01).reshape(10, 10)
Out[35]:
In [35]:
Out[35]:
In [36]:
np.linspace(0,1,20)
Out[36]:
In [36]:
Out[36]:
In [37]:
# HERE IS THE GIVEN MATRIX CALLED MAT
# USE IT FOR THE FOLLOWING TASKS
mat = np.arange(1,26).reshape(5,5)
mat
Out[37]:
In [40]:
mat[2:,1:]
Out[40]:
In [40]:
Out[40]:
In [41]:
mat[3,4]
Out[41]:
In [41]:
Out[41]:
In [53]:
mat[:4,1:2]
Out[53]:
In [52]:
Out[52]:
In [55]:
mat[4,:]
Out[55]:
In [46]:
Out[46]:
In [57]:
mat[3:5,:]
Out[57]:
In [49]:
Out[49]:
In [59]:
mat.sum()
Out[59]:
In [50]:
Out[50]:
In [61]:
mat.std()
Out[61]:
In [51]:
Out[51]:
In [62]:
sum(mat)
Out[62]:
In [53]:
Out[53]:
We worked a lot with random data with numpy, but is there a way we can insure that we always get the same random numbers? Click Here for a Hint
In [66]:
np.random.seed(seed=None)